home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / psdsm103.zip / DOSMEM.PAS next >
Pascal/Delphi Source File  |  1993-01-27  |  3KB  |  190 lines

  1. {
  2.  
  3.                                                       ╔══════════════════╗
  4.                                                       ║  Big DOS Memory  ║
  5.                                                       ║    Allocations   ║
  6.                                                       ║    Rev. 1.03     ║
  7.                                                       ╚══════════════════╝
  8.  
  9. }
  10.  
  11. {$F-} {$O-} {$A+} {$G-}
  12. {$V-} {$B-} {$X-} {$N+} {$E+}
  13.  
  14. {$I FINAL.PAS}
  15.  
  16. {$DEFINE UsingGraph}
  17.  
  18. {$IFDEF FINAL}
  19.   {$I-} {$R-}
  20.   {$D-} {$L-} {$S-}
  21. {$ENDIF}
  22.  
  23. Unit DosMem;
  24.  
  25. Interface
  26.  
  27. {$IFDEF UsingGraph}
  28.  
  29. Uses Graph;
  30.  
  31. {$ENDIF}
  32.  
  33. Procedure GetMem   (Var P:Pointer;Size:LongInt);
  34. Procedure FreeMem  (Var P:Pointer;Size:LongInt);
  35. Function  MaxAvail :LongInt;
  36. Function  MemAvail :LongInt;
  37. Procedure New;
  38. Procedure Dispose;
  39. Procedure Mark;
  40. Procedure Release;
  41.  
  42. {$IFDEF UsingGraph}
  43.  
  44. Function  ImageSize(X1,Y1,X2,Y2:LongInt):LongInt;
  45.  
  46. {$ENDIF}
  47.  
  48. Implementation
  49.  
  50. Procedure GetMem(Var P:Pointer;Size:LongInt);
  51.  
  52. Var
  53.   NewSize  :Word;
  54.   DosSeg   :Word;
  55.  
  56. Begin
  57.   NewSize:=(Size+15) Div 16;
  58.  
  59.   Asm
  60.     mov  ah, 048h
  61.     mov  bx, NewSize
  62.     int  21h
  63.     jnc  @NoErr
  64.     xor  ax, ax         {Return 0 if Error}
  65.     @NoErr:
  66.     mov  DosSeg,ax
  67.   End;
  68.  
  69.   P:=Ptr(DosSeg,0);
  70.  
  71.   {$IFDEF NOTFINAL}
  72.  
  73.   If DosSeg=0 Then              {No Memory Available}
  74.   Repeat
  75.     System.GetMem(P,65535);     {Generate Error 203, Heap Overflow}
  76.   Until False;
  77.  
  78.   {$ENDIF}
  79.  
  80. End;
  81.  
  82. Procedure FreeMem(Var P:Pointer;Size:LongInt);
  83.  
  84. Var
  85.   Segment  :Word;
  86.   Error    :Boolean;
  87.  
  88. Begin
  89.   {$IFDEF NOTFINAL}
  90.  
  91.   If Ofs(P^)<>0 Then
  92.   Begin
  93.     P:=NIL;
  94.     System.FreeMem(P,1);     {Generate Error 204 as Pointer Offset is not 0}
  95.   End;
  96.  
  97.   {$ENDIF}
  98.  
  99.   Segment:=Seg(P^);
  100.  
  101.   Asm
  102.     mov  ax, Segment
  103.     mov  es, ax                 {Set Segment}
  104.  
  105.     xor  al, al
  106.     mov  Error, al              {Assume No Error, Error = False}
  107.  
  108.     mov  ah, 049h
  109.     int  21h
  110.     jnc  @NoErr
  111.     mov  Error, True            {No Zero Value into Segment, Error Occurred}
  112.     @NoErr:
  113.   End;
  114.  
  115.   If Not Error Then
  116.     P:=NIL;                     {P is NIL if No Error, Else No Change}
  117. End;
  118.  
  119. Function MaxAvail:LongInt;
  120.  
  121. Var
  122.   NewSize  :Word;
  123.  
  124. Begin
  125.   Asm
  126.     mov  ah, 048h
  127.     mov  bx, 0FFFFh
  128.     int  21h
  129.     mov  NewSize, bx
  130.   End;
  131.   MaxAvail:=LongInt(NewSize)*16;
  132. End;
  133.  
  134. Function MemAvail:LongInt;
  135. Begin
  136.   MemAvail:=MaxAvail;
  137. End;
  138.  
  139. Procedure New;
  140. Begin
  141.   WriteLn('Not Available, Use GetMem or FreeMem.');
  142.   Halt;
  143. End;
  144.  
  145. Procedure Dispose;
  146. Begin
  147.   WriteLn('Not Available, Use GetMem or FreeMem.');
  148.   Halt;
  149. End;
  150.  
  151. Procedure Mark;
  152. Begin
  153.   WriteLn('Not Available, Use GetMem or FreeMem.');
  154.   Halt;
  155. End;
  156.  
  157. Procedure Release;
  158. Begin
  159.   WriteLn('Not Available, Use GetMem or FreeMem.');
  160.   Halt;
  161. End;
  162.  
  163. {$IFDEF UsingGraph}
  164.  
  165. Function ImageSize(X1,Y1,X2,Y2:LongInt):LongInt;
  166.  
  167. Var
  168.   XSize,
  169.   YSize :Word;
  170.  
  171. Begin
  172.   XSize:=X2-X1+1;
  173.   YSize:=Y2-Y1+1;
  174.   Case GetMaxColor Of
  175.        15:ImageSize:=(((XSize) shr 1) + 1) * YSize + 4;
  176.       255:ImageSize:=XSize * YSize + 4;
  177.     32767,
  178.     65535:ImageSize:=2 * XSize * YSize + 4;
  179.     {16.7 Million - in a Word - Now What?}
  180.   Else
  181.     ImageSize:=Graph.ImageSize(X1,Y1,X2,Y2);
  182.   End;
  183. End;
  184.  
  185. {$ENDIF}
  186.  
  187. End.
  188.  
  189. { Copyright 1993, Michael Gallias }
  190.